<!DOCTYPE html><html lang="zh-CN"><head>
<meta charset="utf-8">
<meta name="X-UA-Compatible" content="IE=Edge, chrome=1">
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<title>地区验证</title>
{php echo register_jssdk(false);}
<link type="text/css" rel="stylesheet" href="{$_W['siteroot']}addons/tiger_jifenbao/template/js/sweetalert.css"/>
<script type="text/javascript" src="{$_W['siteroot']}app/resource/js/lib/jquery-1.11.1.min.js"></script>
<script src="{$_W['siteroot']}addons/tiger_jifenbao/template/js/sweetalert.min.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=mVzo3bHzRIApG1Oi72i3z59Y"></script>
</head>
<body>
<script>
wx.ready(function(){
$(function(){
var xddq="{$settings['locationtype']}";
var gpsdq=localStorage.getItem("getLocation");
var ipdq='{$city}';
var scene_id='{$scene_id}';
var from_user='{$from_user}';
var ipprovince='{$province}';
var ipdistrict='{$district}';
var xzdqd='{$settings["city"]}';
if(xddq==2){
  if(!(xzdqd.indexOf(ipdq)>-1)){
       $.ajax({
          url:"{php echo $this->createMobileUrl('fwajxdiqu',array('uid'=>$uid))}",
               type:'post',
               data:{
                  province:ipprovince,
                  city:ipdq,
                  district:ipdistrict,
                  from_user:from_user,
                  scene_id:scene_id,
               },
               dataType:"json", 
               success:function(data){
               }
        });
       swal({
            title: "尊敬的粉丝!",
            text: "很抱歉，你不在活动区域",
            type: "warning",    
            confirmButtonColor: "#DD6B55",  
            confirmButtonText: "关闭返回",   
            closeOnConfirm: false},
            function(){   
                wx.closeWindow();
            });
     }else{
       $.ajax({
          url:"{php echo $this->createMobileUrl('fwajxdiqu',array('uid'=>$uid))}",
               type:'post',
               data:{
                  province:ipprovince,
                  city:ipdq,
                  district:ipdistrict,
                  from_user:from_user,
                  scene_id:scene_id,
               },
               dataType:"json", 
               success:function(data){
               }
        });
       swal({title: "位置核对成功",   
              text: "赶快去点击菜单-【生成海报】吧！",  
              type: "success",    
              confirmButtonColor: "#DD6B55",  
              confirmButtonText: "确定",   closeOnConfirm: false }, 
              function(){   
                wx.closeWindow();
          });
     }
}

if(xddq==0){
  if(!(xzdqd.indexOf(ipdq)>-1)){
       $.ajax({
          url:"{php echo $this->createMobileUrl('fwajxdiqu',array('uid'=>$uid))}",
               type:'post',
               data:{
                  province:ipprovince,
                  city:ipdq,
                  district:ipdistrict,
                  from_user:from_user,
                  scene_id:scene_id,
               },
               dataType:"json", 
               success:function(data){
               }
        });
       swal({
            title: "尊敬的粉丝!",
            text: "很抱歉，你不在活动区域",
            type: "warning",    
            confirmButtonColor: "#DD6B55",  
            confirmButtonText: "关闭返回",   
            closeOnConfirm: false},
            function(){   
                wx.closeWindow();
            });
     }else{
       $.ajax({
          url:"{php echo $this->createMobileUrl('fwajxdiqu',array('uid'=>$uid))}",
               type:'post',
               data:{
                  province:ipprovince,
                  city:ipdq,
                  district:ipdistrict,
                  from_user:from_user,
                  scene_id:scene_id,
               },
               dataType:"json", 
               success:function(data){
               }
        });
       swal({title: "位置核对成功",   
              text: "赶快去点击菜单-【生成海报】吧！",  
              type: "success",    
              confirmButtonColor: "#DD6B55",  
              confirmButtonText: "确定",   closeOnConfirm: false }, 
              function(){   
                wx.closeWindow();
          });
     }
}
	
	 //alert(localStorage.getItem("getLocation")+"kk"+"{$settings["city"]}");
    //非gps定位。则不去抓地址。
	{if empty($settings["city"]) || empty($settings["locationtype"])}
       //$(".submit").show();
       //swal('我也要参加活动!')
       //swal("", "马上开始活动", "success");
    {else}
    //地址只抓一次。
 	if (localStorage.getItem("getLocation") && localStorage.getItem("getLocation")=="{$settings["city"]}"){
	   // alert(localStorage.getItem("getLocation")+"zz"+"{$settings["city"]}");
		//$(".submit").show();
        //swal('我也要参加活动!');
        $.ajax({
          url:"{php echo $this->createMobileUrl('fwajxdiqu',array('uid'=>$uid))}",
               type:'post',
               data:{
                  city:localStorage.getItem("getLocation"),
                  from_user:from_user,
                  scene_id:scene_id,
               },
               dataType:"json", 
               success:function(data){
               }
        });
        swal({title: "位置核对成功",   
              text: "你可以参加活动了哦，不需要重复核对位置",  
              type: "success",    
              confirmButtonColor: "#DD6B55",  
              confirmButtonText: "确定",   closeOnConfirm: false }, 
              function(){   
                wx.closeWindow();
        });
	 } else { 
         if(xddq==1){
           getLocation(); 
         }	   
	  } 
    {/if}
  
  
 });
  function errorPosition(){
      $.ajax({
          url:"{php echo $this->createMobileUrl('fwajxdiqu',array('uid'=>$uid))}",
               type:'post',
               data:{
                  ddtype:1,
                  city:localStorage.getItem("getLocation"),
                  from_user:from_user,
                  scene_id:scene_id,
               },
               dataType:"json", 
               success:function(data){
               }
        });
     swal({
            title: "尊敬的粉丝!",
            text: "1、请刷新重试，请允许获取地理位置信息。2、检查手机是否打开GPS地理位置定位功能。",
            type: "warning",    
            confirmButtonColor: "#DD6B55",  
            confirmButtonText: "关闭重试",   
            closeOnConfirm: false},
            function(){   
                wx.closeWindow();
            });
	
}
function getLocation(){
    var options={
        enableHighAccuracy:true, 
        maximumAge:1000
    }
   swal({title: "系统加载中",text: "请耐心等待",showConfirmButton: false});
    if(navigator.geolocation){
        //浏览器支持geolocation
        navigator.geolocation.getCurrentPosition(showPosition,errorPosition,options);
        
    }else{
        //浏览器不支持geolocation
    }
}
function errorPosition(error){
    $.ajax({
          url:"{php echo $this->createMobileUrl('fwajxdiqu',array('uid'=>$uid))}",
               type:'post',
               data:{
                  ddtype:1,
                  city:localStorage.getItem("getLocation"),
                  from_user:from_user,
                  scene_id:scene_id,
               },
               dataType:"json", 
               success:function(data){
               }
        });
    swal({
            title: "尊敬的粉丝!",
            text: "1、请刷新重试，请允许获取地理位置信息。2、检查手机是否打开GPS地理位置定位功能。",
            type: "warning",    
            confirmButtonColor: "#DD6B55",  
            confirmButtonText: "关闭重试",   
            closeOnConfirm: false},
            function(){   
                wx.closeWindow();
            });
	
}
function showPosition(position)
{
console.log(position.coords.latitude +
"<br />Longitude: " + position.coords.longitude);

var location= position.coords.latitude+"," + position.coords.longitude;
//alert(location);
/* var point = new BMap.Point(116.331398,39.897445); */

	var point = new BMap.Point(position.coords.longitude,position.coords.latitude);
	var geoc = new BMap.Geocoder(); 
	
	geoc.getLocation(point, function(rs){
		var address = rs.addressComponents;
		//alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
		var diqu="{$settings["city"]}".split(",");
   	    var str=address.province+","+address.city+","+address.district;
   	    var dw=false;
   	    $.each(diqu, function(i, item){ 
   		     if (str.indexOf(item)>-1) {
   		    	 dw=true;
   		    	 $(".submit").show();
   				 localStorage.setItem("getLocation", "{$settings["city"]}"); 
                 return false;
   		     }  
   		 }); 
   	  if (dw==false) {
            $.ajax({
              url:"{php echo $this->createMobileUrl('fwajxdiqu',array('uid'=>$uid))}",
                   type:'post',
                   data:{
                      province:address.province,
                      city:address.city,
                      district:address.district,
                      from_user:from_user,
                      scene_id:scene_id,
                   },
                   dataType:"json", 
                   success:function(data){
                   }
            });
      		swal({
                title: "尊敬的粉丝!",
                text: "很抱歉，你不在活动区域",
                type: "warning",    
                confirmButtonColor: "#DD6B55",  
                confirmButtonText: "关闭返回",   
                closeOnConfirm: false},
                function(){   
                    wx.closeWindow();
            });
   	  }	  else {
		  swal({title: "位置核对成功",   
              text: "赶快去点击菜单-【生成海报】吧！",  
              type: "success",    
              confirmButtonColor: "#DD6B55",  
              confirmButtonText: "确定",   closeOnConfirm: false }, 
              function(){   
                wx.closeWindow();
          });
	  }
   	 
   		return;
   	});
	return;
//百度接口，一天可以调用100w次，此处注释。
var url="http://api.map.baidu.com/geocoder/v2/"+
 "?ak=mVzo3bHzRIApG1Oi72i3z59Y&callback=renderReverse&location="+location+"&output=json&pois=0";
$.ajax({
      type : "get",
      async:false,
      url : url,
      dataType : "jsonp",
      jsonp: "callback",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(默认为:callback)
      jsonpCallback:"renderReverse",//自定义的jsonp回调函数名称，默认为jQuery自动生成的随机函数名
      success : function(json){
          if (json.status=="0"){
           	  var address=json.result.addressComponent;
        	  var diqu="{$settings["city"]}".split(",");
        	  var str=address.province+","+address.city+","+address.district;
        	  var dw=false;
        	  $.each(diqu, function(i, item){ 
        		     if (str.indexOf(item)>-1) {
        		    	 dw=true;
        		    	 $(".submit").show();
        				 localStorage.setItem("getLocation", "{$settings["city"]}"); 
                         return false;
        		     }  
        		 }); 
        	  if (dw==false) {
                $.ajax({
                  url:"{php echo $this->createMobileUrl('fwajxdiqu',array('uid'=>$uid))}",
                       type:'post',
                       data:{
                          province:address.province,
                          city:address.city,
                          district:address.district,
                          from_user:from_user,
                          scene_id:scene_id,
                       },
                       dataType:"json", 
                       success:function(data){
                       }
                });
           		swal({
                    title: "尊敬的粉丝!",
                    text: "很抱歉，你不在活动区域",
                    type: "warning",    
                    confirmButtonColor: "#DD6B55",  
                    confirmButtonText: "关闭返回",   
                    closeOnConfirm: false},
                    function(){   
                        wx.closeWindow();
                });
        		return;
        	    //$(".layer").fadeIn();
                //$(".layer-city").fadeIn();
                //$("#citydesc").text(str);
                swal({
                    title: "尊敬的粉丝!",
                    text: "很抱歉，你不在活动区域",
                    type: "warning",    
                    confirmButtonColor: "#DD6B55",  
                    confirmButtonText: "关闭返回",   
                    closeOnConfirm: false},
                    function(){   
                        wx.closeWindow();
                });
        	  } else {
        		  swal({title: "位置核对成功",   
                      text: "你可以参加活动了哦，不需要重复核对位置",  
                      type: "success",    
                      confirmButtonColor: "#DD6B55",  
                      confirmButtonText: "确定",   closeOnConfirm: false }, 
                      function(){   
                        wx.closeWindow();
                  });
        	  }
        	
          } else {
              swal({
                    title: "尊敬的粉丝!",
                    text: "获取定位失败",
                    type: "warning",    
                    confirmButtonColor: "#DD6B55",  
                    confirmButtonText: "关闭返回",   
                    closeOnConfirm: false},
                    function(){   
                        wx.closeWindow();
                });
        }
      },
      error:function(){
          swal({
                    title: "尊敬的粉丝!",
                    text: "获取定位失败",
                    type: "warning",    
                    confirmButtonColor: "#DD6B55",  
                    confirmButtonText: "关闭返回",   
                    closeOnConfirm: false},
                    function(){   
                        wx.closeWindow();
                });
      }
  });

}
	
});
</script>
</body>
</html>
